﻿using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.SetObstacleActivation, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_SetObstacleActivation : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.SetObstacleActivation;

        public override string name => LevelEditorConst.SetObstacleActivation;
        [Output("目标", false)] public EditorLevelServiceDynamicListSetter tagOrMcid;
        [InspectorName("激活阻挡(关门)"), Tooltip("否为取消激活(开门)")] public bool isObstacleActive;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_SetObstacleActivation()
            {
                // tagOrMcid = this.tagOrMcid,
                isObstacleActive = this.isObstacleActive,
                tagOrMcid = LevelServiceDynamicListSelectNode.DefaultParam
            };
            this.tagOrMcid = new EditorLevelServiceDynamicListSetter((x) => rConfig.tagOrMcid = x);
            return rConfig;
        }
        
        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_SetObstacleActivation rNode)
            {
                this.isObstacleActive = rNode.isObstacleActive;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_SetObstacleActivation rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid);
            }
        }
    }
}